package com.ruoyi.web.controller.warehouse;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehouse.domain.WareHouseSnail;
import com.ruoyi.warehouse.service.IWareHouseSnailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 螺Controller
 * 
 * @author 杨彬鑫
 * @date 2021-01-29
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/warehouse/snail" )
public class SnailController extends BaseController {

    private final IWareHouseSnailService iWareHouseSnailService;

    /**
     * 查询螺列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:snail:list')")
    @GetMapping("/list")
    public TableDataInfo list(WareHouseSnail wareHouseSnail) {
        startPage();
        List<WareHouseSnail> list = iWareHouseSnailService.queryList(wareHouseSnail);
        return getDataTable(list);
    }

    /**
     * 导出螺列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:snail:export')" )
    @Log(title = "螺" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(WareHouseSnail wareHouseSnail) {
        List<WareHouseSnail> list = iWareHouseSnailService.queryList(wareHouseSnail);
        ExcelUtil<WareHouseSnail> util = new ExcelUtil<WareHouseSnail>(WareHouseSnail.class);
        return util.exportExcel(list, "snail" );
    }

    /**
     * 获取螺详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:snail:query')" )
    @GetMapping(value = "/{snailCode}" )
    public AjaxResult getInfo(@PathVariable("snailCode" ) String snailCode) {
        return AjaxResult.success(iWareHouseSnailService.getById(snailCode));
    }

    /**
     * 新增螺
     */
    @PreAuthorize("@ss.hasPermi('warehouse:snail:add')" )
    @Log(title = "螺" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WareHouseSnail wareHouseSnail) {
        return toAjax(iWareHouseSnailService.save(wareHouseSnail) ? 1 : 0);
    }

    /**
     * 修改螺
     */
    @PreAuthorize("@ss.hasPermi('warehouse:snail:edit')" )
    @Log(title = "螺" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WareHouseSnail wareHouseSnail) {
        return toAjax(iWareHouseSnailService.updateById(wareHouseSnail) ? 1 : 0);
    }

    /**
     * 删除螺
     */
    @PreAuthorize("@ss.hasPermi('warehouse:snail:remove')" )
    @Log(title = "螺" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{snailCodes}" )
    public AjaxResult remove(@PathVariable String[] snailCodes) {
        return toAjax(iWareHouseSnailService.removeByIds(Arrays.asList(snailCodes)) ? 1 : 0);
    }
}
